package com.marketingexpert.dao.ibatis;

import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.marketingexpert.dao.TaskDao;
import com.marketingexpert.domain.Task;
import com.marketingexpert.domain.TaskWeiboId;
import com.marketingexpert.domain.WeiboContent;

public class SqlMapTaskDao extends SqlMapClientDaoSupport implements TaskDao {

	public List<Task> queryTaskByUserId(String userId)
			throws DataAccessException {
		List<Task> tasks = null;
		try {
			tasks = getSqlMapClientTemplate().queryForList("selectTaskByUserId",userId);
			return tasks;
			} catch(DataAccessException e) {
				e.printStackTrace();
				throw e;
			}
	}

	public Task queryTaskById(int taskId) throws DataAccessException {
		try {
			return (Task) getSqlMapClientTemplate().queryForObject("selectTaskById", taskId);
		} catch(DataAccessException e) {
			e.printStackTrace();
			throw e;
		}
	}

	public int insertTask(Task task) throws DataAccessException {
		try {
			int taskId = (Integer)getSqlMapClientTemplate().insert("insertTask",task);
			return taskId;
			} catch(DataAccessException e) {
				e.printStackTrace();
				throw e;
			}
	}

	public int insertWeiboContent(WeiboContent weiboContent) {
		try {
			int weiboContentId = (Integer)getSqlMapClientTemplate().insert("insertWeibocontent",weiboContent);
			return weiboContentId;
			} catch(DataAccessException e) {
				e.printStackTrace();
				throw e;
			}
	}

	public int insertTaskWeiboId(TaskWeiboId taskWeiboId) {
		try {
			int taskWeiboId_ID = (Integer)getSqlMapClientTemplate().insert("insertTaskWeiboId",taskWeiboId);
			return taskWeiboId_ID;
			} catch(DataAccessException e) {
				e.printStackTrace();
				throw e;
			}
	}

	public void deleteTaskById(int taskId) {
		try {
			getSqlMapClientTemplate().delete("deleteTask", taskId);
		} catch(DataAccessException e) {
			e.printStackTrace();
			throw e;
		}
		
	}

	public List<Task> queryMessage(Task task) {
		try {
			return getSqlMapClientTemplate().queryForList("queryMessageByUserIdAndType",task);
		} catch(DataAccessException e) {
			e.printStackTrace();
			throw e;
		}
	}

	public void deleteTaskByIdAndType(Task t) throws DataAccessException {
		try {
			getSqlMapClientTemplate().delete("deleteTaskByIdAndType", t);
		} catch(DataAccessException e) {
			e.printStackTrace();
			throw e;
		}
	}

	public void batchDeleteTask(String[] taskIds)
			throws DataAccessException {
		try {
			getSqlMapClientTemplate().delete("batchDeleteTask", taskIds);
		} catch(DataAccessException e) {
			e.printStackTrace();
			throw e;
		}
		
	}

	public int updateTask(Task task) throws DataAccessException {
		try {
			return (Integer)getSqlMapClientTemplate().update("updateTask",task);
			} catch(DataAccessException e) {
				e.printStackTrace();
				throw e;
			}
	}

	public TaskWeiboId queryWeiboUserIdByTaskIdAndWUId(TaskWeiboId taskWeiboId)
			throws DataAccessException {
		try {
			return (TaskWeiboId) getSqlMapClientTemplate().queryForObject("queryWeiboUserIdByTaskIdAndWUId", taskWeiboId);
		} catch(DataAccessException e) {
			e.printStackTrace();
			throw e;
		}
	}

}
